<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\validate\AdminMenuValidate;
use Redis\Redis;
use think\App;
use app\admin\model\AdminMenus as AdminMenusModel;
use think\facade\View;

class Adminmenus extends Common
{
    protected $modelClass = AdminMenusModel::class;
    protected $validator   = AdminMenuValidate::class;

    public function __construct(App $app)
    {
        parent::__construct($app);

        // 筛选的菜单列表
        $list = $this->model ? $this->model->getSelectLists([], ['menu_sort' => 'ASC']) : [];
        View::assign('menus', $list);
    }

    protected function setSearchWhereFilter(array &$params = []):void
    {
        parent::setSearchWhereFilter($params); // TODO: Change the autogenerated stub

        if (isset($params['search']) && !empty($params['search'])){
            $params['where'][] = ['role_name', 'like', '%' . $params['search'] . '%'];
        }

        if (!isset($params['parent_id'])) $params['parent_id'] = 0;
        if ( isset($params['parent_id']) && $params['parent_id'] > -1 ) {
            $params['where'][] = ['parent_id', '=', $params['parent_id']];
        }

        // 默认排序
        $params['order'] = ['menu_sort', 'ASC'];
    }
}
